package com.subaiqiao.yunshiyuan.config.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动填充策略
 * @author caochaoyu
 */

@Slf4j
@Component //一定不要忘记把处理器添加到IOC容器中！
public class MyMetaObjectHandler implements MetaObjectHandler {
    /**
     * 插入时的填充策略
     */

    @Override
    public void insertFill(MetaObject metaObject) {
        // 起始版本 3.3.3(推荐)
        this.strictInsertFill(metaObject, "createDatetime", Date.class, new Date());
        this.strictUpdateFill(metaObject, "updateDatetime", Date.class, new Date());
    }

    /**
     * 更新时的填充策略
     */

    @Override
    public void updateFill(MetaObject metaObject) {
        // 起始版本 3.3.3(推荐)
        this.strictUpdateFill(metaObject, "updateDatetime", Date.class, new Date());
    }
}
